package com.ld.security.auth.common.base.service.impl;

import com.ld.security.auth.common.base.constants.JwtFunctionConstant;
import com.ld.security.auth.common.base.entity.JwtFunction;
import com.ld.security.common.core.base.column.ListString;
import com.ld.security.common.core.util.GenericUtil;
import com.ld.security.common.core.util.ReflectionUtil;
import com.ld.security.common.core.util.UuidUtil;
import com.ld.security.common.mybatis.base.entity.TreeEntity;
import org.springframework.beans.factory.annotation.Value;

public abstract class InitAppServie<E extends JwtFunction> {

    @Value("${spring.application.name}")
    protected String appName ;

    @Value("${info.title}")
    protected String appDesc;


    public abstract void initSystem();


    protected E getRoot(){
        Class<E> clazz =  this.getEntityClass();
        E root =  ReflectionUtil.newInstance(clazz);

        root.setParentPath(new ListString(TreeEntity.root));
        root.setUrl(TreeEntity.separator+ appName);
        root.setId(UuidUtil.getId(root.getUrl()));
        root.setFuncType(JwtFunctionConstant.funcType.api);

        root.setLabel(appDesc);
        return root;
    }

    protected Class<E> getEntityClass()
    {
        return (Class<E>) GenericUtil.getGeneric(this.getClass(), InitAppServie.class, 0);
    }

}
